﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace Jäckvik_Grupp4
{
    public partial class Invoice : Form
    {
        private LOGIC.LogicInvoice invoice = new LOGIC.LogicInvoice();
        private int tempInvoiceID;
        private int tempBookingID;


    
        public Invoice(LOGIC.LogicInvoice invoice, int tempInvoiceID, int tempBookingID)
        {
            InitializeComponent();
         
            string invoicedetails = invoice.GetInvoice(tempBookingID)[1].ToString();
            string[] invoiceSplit = invoicedetails.Split('\t');
            this.invoice = invoice;
            this.tempInvoiceID = tempInvoiceID;
            this.tempBookingID = tempBookingID;

                double InvoiceSum = (double.Parse(invoiceSplit[11]) * 0.85); 
                double sumNoVat = (InvoiceSum * 0.88);//29);

                double Vat = double.Parse(invoiceSplit[11]) - sumNoVat;

                labelInvoiceID.Text = invoiceSplit[1];
                labelGuestNr.Text = invoiceSplit[2];
                labelGuestName.Text = invoiceSplit[3] + " " + invoiceSplit[4];
                labelAdress.Text = invoiceSplit[5];
                labelZipAndCity.Text = invoiceSplit[6];
                labelStaffName.Text = invoiceSplit[7] + " " + invoiceSplit[8];
                labelPrintDate.Text = invoiceSplit[9];
                labelPayDate.Text = invoiceSplit[10];
                labelTotalSumToPay.Text = InvoiceSum.ToString();
                labelSumExVac.Text = sumNoVat.ToString();
                labelVatSum.Text = Vat.ToString();
                labelReference.Text = invoiceSplit[3] + " " + invoiceSplit[4];

                // listBoxInvoice.DataSource = logicInvoice.GetInvoice(tempBookingID);
                listBoxInvoice.DataSource = invoice.GetWholeInvoice(tempBookingID);
            
        }

        private void Invoice_Load(object sender, EventArgs e)
        {
            SaveAsBitMap(this, "C:\\"+tempBookingID+"A.bmp");        
        }
        public void SaveAsBitMap(Control control, string fileName)
        {
            Graphics g = control.CreateGraphics();
            Bitmap bmp = new Bitmap(control.Width, control.Height);
            control.DrawToBitmap(bmp,new Rectangle(0,0,control.Width,control.Height));
        bmp.Save(fileName);
            bmp.Dispose();
            g.Dispose();
        }

     
    }
}
